package com.bonc.cq.cloud.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @author fengyong
 * @version V1.0
 * @Title:
 * @Description: 使用spring cloud 原生的redis方式限流 自定义resolver
 * @date 2019-08-03 17:14
 */
@Configuration
public class CustomResolver {
    @Bean
    public KeyResolver ipKeyResolver(){
        System.out.println("##############ipKeyResolver 根据请求IP地址来限流########################");
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
    }
//    @Bean
//    KeyResolver userKeyResolver() {
//        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user"));
//    }
}
